<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;

class PageController extends LoginController {
	public function __construct() {
		parent::__construct ();
		// S(array('type'=>'File','prefix'=>'cate','expire'=>60));
		layout ( false );
	}
	public function index() {
		$this->db = D ( "Page" ); // 实例化Data数据对象
		$count = $this->db->count (); // 查询满足要求的总记录数 $map表示查询条件
		$Page = page ( $count );
		$show = $Page->show (); // 分页显示输出
		                             // 进行分页数据查询
		$list = $this->db->field ( "id,title,up_date" )->limit ( $Page->firstRow . ',' . $Page->listRows )->select ();
		$this->assign ( 'list', $list ); // 赋值数据集
		$this->assign ( 'show', $show ); // 赋值分页输出
		$this->display ( 'index' ); // 输出模板
	}
	public function getPage() {
		$data = array ();
		if (!empty($_GET['id'])) {
			$this->db = D ( "Page" ); // 实例化Data数据对象
			$id = $_GET ['id'];
			$data = $this->db->find ( $id );
		}
		$this->assign ( "data", $data );
		$this->display ( "add" );
	}
	
	// 保存单页面数据
	public function savePage() {
		$this->db = D ( "Page" );
		if ($_POST) {
			$this->checkToken($_POST);
			$arr = $_POST;
			// 新增
			$arr ['up_date'] = date ( "Y-m-d H:i:s" );
			$id = $arr ['id'];
			if (empty ( $_POST ['id'] )) {
				$arr ['creat_date'] = $arr ['up_date'];
				$id = $this->db->add ( $arr );
			}
			$this->db->where ( "id=$id" )->save ( $arr );
			redirect ( 'index' );
		}
	}
	public function pageDe() {
		if (IS_POST) {
			$id = $_POST ['id'];
			$this->db = D ( 'Page' );
			echo $this->db->where ( "id=$id" )->delete ();
		}
	}
}
?>